{% extends "base.html" %}
{% load render_table from django_tables2 %}
{% block title %} List Flags | sh00t{% endblock %}

{% block page %}
<ol class="breadcrumb">
    <li class="breadcrumb-item"><a href="/">Dashboard</a></li>
    <li class="breadcrumb-item active"> <i class="fa fa-flag"></i> All Flags</li>
</ol>
<div class="row">
    <div class="col-lg-12">
        <div class="panel panel-default">
            <div class="panel-body">
                {% if count > 0 %}
                    {% render_table table %}
                    <div class="left">
                        <input type="button" value="Delete" id="delBtn" class="btn btn-danger" data-loading-text="Deleting.." />
                {% else %}
                    <h4>No flags yet. <a href="/app/flags/new">Add a flag</a> </h4>
                {% endif %}
            </div>
        </div>
    </div>
</div>
{% endblock %}
{% block extra_foot %}
<script src="/static/js/common-ajax.js"></script>
<script language="javascript">
$('#delBtn').on('click', function() {
    if(isCheckedMin()) {
        if(confirm("You are about to delete the selected flag/s. Are you sure to continue?")) {
            var $this = $(this);
            $this.button('loading');
            $('input:checked').each(function() {
                $.ajax({
                    url: '/api/flag/' + $(this).val(),
                    type: 'DELETE',
                    headers: {"X-CSRFToken": getCSRFToken()},
                });
            });
            alert("The selected flag/s have been deleted");
            document.location.reload();
        }
    } else
        $("#checkMin1").modal();
});
</script>
{% include "include/delete-validation-modal.html" %}
{% endblock %}